<!DOCTYPE html>
<html>
<head>
    <title>Physics Diagram - Induced EMF</title>
</head>
<body>
<canvas id="physicsCanvas" width="500" height="550" style="border:1px solid #000;"></canvas>
<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // Define parameters and coordinates
    const cx = canvas.width / 2;
    const cy = 190;
    const a = 130; // Represents length 'a' in pixels (radius and top base)
    
    ctx.lineWidth = 1.5;
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';

    // Function to draw a cross 'x'
    function drawCross(x, y, size) {
        ctx.beginPath();
        ctx.moveTo(x - size, y - size);
        ctx.lineTo(x + size, y + size);
        ctx.moveTo(x + size, y - size);
        ctx.lineTo(x - size, y + size);
        ctx.stroke();
    }

    // 1. Draw the circular magnetic field region
    ctx.beginPath();
    ctx.arc(cx, cy, a, 0, 2 * Math.PI);
    ctx.stroke();

    // 2. Draw the magnetic field crosses inside the circle
    const crossSize = 6;
    const crossPositions = [
        {x: 0, y: 0},
        {x: -0.4*a, y: -0.1*a}, {x: 0.4*a, y: -0.1*a},
        {x: 0, y: -0.5*a},
        {x: -0.7*a, y: -0.4*a}, {x: 0.7*a, y: -0.4*a},
        {x: -0.4*a, y: -0.7*a}, {x: 0.4*a, y: -0.7*a},
        {x: -0.8*a, y: 0.2*a}, {x: 0.8*a, y: 0.2*a},
        {x: -0.4*a, y: 0.5*a}, {x: 0.4*a, y: 0.5*a},
        {x: 0, y: 0.7*a}
    ];

    crossPositions.forEach(pos => {
        // Ensure crosses are strictly inside the circle for clarity
        if (Math.sqrt(pos.x*pos.x + pos.y*pos.y) < a - crossSize*2) {
             drawCross(cx + pos.x, cy + pos.y, crossSize);
        }
    });

    // 3. Define the trapezoid vertices
    // Triangle OAD is equilateral since OA=OD=AD=a
    // Height of OAD from O to chord AD
    const h_OAD = a * Math.sqrt(3) / 2;
    // Height of the trapezoid itself (estimated from diagram)
    const h_trap = a * 0.9;

    // Coordinates of vertices
    const Ax = cx - a / 2;
    const Ay = cy + h_OAD;
    const Dx = cx + a / 2;
    const Dy = Ay;

    const Bx = cx - a; // Bottom base is 2a wide, centered
    const By = Ay + h_trap;
    const Cx = cx + a;
    const Cy = By;

    // 4. Draw the trapezoid wire loop ABCD
    ctx.beginPath();
    ctx.moveTo(Ax, Ay);
    ctx.lineTo(Bx, By);
    ctx.lineTo(Cx, Cy);
    ctx.lineTo(Dx, Dy);
    ctx.lineTo(Ax, Ay); // Close the loop
    ctx.lineWidth = 2;
    ctx.stroke();
    ctx.lineWidth = 1.5; // Reset line width

    // 5. Draw dashed lines from center O to A and D
    ctx.beginPath();
    ctx.setLineDash([4, 4]);
    ctx.moveTo(cx, cy);
    ctx.lineTo(Ax, Ay);
    ctx.moveTo(cx, cy);
    ctx.lineTo(Dx, Dy);
    ctx.stroke();
    ctx.setLineDash([]); // Reset to solid line

    // 6. Draw labels
    ctx.font = "italic 20px Times New Roman";
    
    // Vertex labels
    ctx.fillText("O", cx - 6, cy - 8);
    ctx.fillText("A", Ax - 22, Ay + 5);
    ctx.fillText("B", Bx - 22, By + 8);
    ctx.fillText("C", Cx + 8, Cy + 8);
    ctx.fillText("D", Dx + 8, Dy + 5);

    // Length labels
    // For 'a', draw a small arc under AD to match the style
    ctx.beginPath();
    ctx.moveTo(Ax, Ay + 4);
    ctx.quadraticCurveTo(cx, Ay + 15, Dx, Dy + 4);
    ctx.lineWidth = 1;
    ctx.stroke();
    ctx.fillText("a", cx - 5, Ay + 25);
    
    ctx.font = "italic 20px Times New Roman";
    ctx.fillText("2a", cx - 15, Cy + 25);
    
    // Chinese text at the bottom
    ctx.font = "22px KaiTi";
    ctx.textAlign = "center";
    ctx.fillText("习题 9-16 图", cx, canvas.height - 20);

</script>
</body>
</html>